home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / asm / fdtools11.lha / fd2pragma.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-27  |  2.3 KB  |  100 lines

  1. /* fd2pragma.c - generate .h file with #pragma (lib|tag)calls */
  2.  
  3. #include "fdparse.h"
  4. #include <string.h>
  5. #include <proto/dos.h>
  6.  
  7. #define BUFFLEN 256
  8.  
  9. extern void addext(STRPTR buff,LONG len,STRPTR orig,STRPTR xt);
  10.  
  11. void fprintfd(BPTR outfile,struct fd *fd,STRPTR pragtype)
  12.  
  13. {
  14.   int i;
  15.  
  16.   if(fd->fd_State & FD_PRIVATE) FPrintf(outfile,"/*");
  17.   FPrintf(outfile,"#pragma %scall %s %s %lx ",pragtype,
  18.                                               fd->fd_BaseName+1,
  19.                                               fd->fd_Function,
  20.                                               -fd->fd_Offset);
  21.   for(i = fd->fd_NumParams-1;i >= 0;i--)  
  22.     FPrintf(outfile,"%lx",fd->fd_Parameter[i]);
  23.   FPrintf(outfile,"0%lx",fd->fd_NumParams);
  24.   if(fd->fd_State & FD_PRIVATE) FPrintf(outfile,"*/");
  25.   FPrintf(outfile,"\n");
  26. }
  27.  
  28. long __oslibversion = 37;
  29.  
  30. UBYTE verstag[] = "$VER: fd2pragma 1.1 " __AMIGADATE__ ;
  31.  
  32. UBYTE template[] = "FDFILE/A,INCFILE/A";
  33.  
  34. LONG args[2] = { 0, 0};
  35.  
  36. int main(int argc,char **argv)
  37.  
  38. {
  39.   int retval = 0;
  40.   struct RDArgs *rda;
  41.   UBYTE buff[BUFFLEN];
  42.   BPTR infile = 0,outfile = 0;
  43.   struct fd fd;
  44.  
  45.   if(argc == 0) return(20); /* we do not run from WB */
  46.  
  47.   rda = ReadArgs(template,args,0);
  48.   if(rda) {
  49.     addext(buff,BUFFLEN,(STRPTR)args[0],".fd");
  50.     infile = Open(buff,MODE_OLDFILE);
  51.     if(!infile) {
  52.       Printf("Could not open .fd file !\n");
  53.       retval = 10;
  54.     }
  55.  
  56.     addext(buff,BUFFLEN,(STRPTR)args[1],".h");
  57.     outfile = Open(buff,MODE_NEWFILE);
  58.     if(!outfile) {
  59.       Printf("Could not open include file !\n");
  60.       retval = 10;
  61.     }
  62.  
  63.     FreeArgs(rda);
  64.   }
  65.   else retval = 10;
  66.  
  67.   if(!retval) {
  68.     InitFD(infile,&fd);
  69.  
  70.     do {
  71.       switch(ParseFD(&fd)) {
  72.         case FD_KEYWORD:
  73.           break;
  74.         case FD_FUNCTION:
  75.           fprintfd(outfile,&fd,"lib");
  76.           if(LibCallAlias(&fd)) fprintfd(outfile,&fd,"lib");
  77.           if(TagCallName(&fd)) {
  78.             FPrintf(outfile,"#ifdef __SASC_60\n");
  79.             fprintfd(outfile,&fd,"tag");
  80.             FPrintf(outfile,"#endif\n");
  81.           }
  82.           break;
  83.         case FD_ERROR:
  84.           Printf("%s\n",fd.fd_Function);
  85.           retval = 10;
  86.           goto error;
  87.         case FD_COMMENT:
  88.           FPrintf(outfile,"/%s*/\n",fd.fd_Function);
  89.           break;
  90.       }
  91.     } while(!(fd.fd_State & FD_READY));
  92.   }
  93.   
  94. error:
  95.   if(outfile) Close(outfile);
  96.   if(infile) Close(infile);
  97.   
  98.   return(retval);
  99. }
  100.